home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tpl60n19.zip / ARISOURC.ZIP / FP48CMP.ASM < prev    next >
Assembly Source File  |  1993-01-24  |  3KB  |  81 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 6.0        *
  5. ; *     Real Comparison                                 *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1989-1992 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   FP48CMP
  12.  
  13.              INCLUDE SE.ASM
  14.  
  15.  
  16. CODE         SEGMENT BYTE PUBLIC
  17.  
  18.              ASSUME  CS:CODE
  19.  
  20. ; Publics
  21.  
  22.              PUBLIC  CmpMantissa,CmpAbsValue,RCmp
  23.  
  24. ;-------------------------------------------------------------------------------
  25. ; RealCmp compares two numbers in the TURBO-Pascal six byte real format. The
  26. ; flags are set as if two unsigned integers had been compared with the 80x86
  27. ; CMP instruction. If op1 > op2, neither carry nor zero flag are set. If
  28. ; op1 = op2 then the zero flag is set and if op1 < op2 then the carry flag is
  29. ; set. CmpAbsValue is an additional entry to the comparison routine that
  30. ; requires that both arguments are positive. Entry CmpMantissa is provided for
  31. ; arguments that are both positive and have identical exponents.
  32. ;
  33. ; INPUT:     DX:BX:AX  first number (op1)
  34. ;            DI:SI:CX  second number (op2)
  35. ;
  36. ; OUTPUT:    CF        set if op1 < op2
  37. ;            ZF        set if op1 = op2
  38. ;
  39. ; DESTROYS:  Flags
  40. ;-------------------------------------------------------------------------------
  41.  
  42. RCmp         PROC    FAR
  43.              XOR     DX, DI            ; sign equal ?
  44.              JNS     $sign_eq          ; yes
  45.              XOR     DX, DI            ; restore DX
  46.              CMP     DI, DX            ; negative number bigger, reverse compare
  47. $exit1:      RET                       ; exit
  48. $sign_eq:    XOR     DX, DI            ; restore DX
  49.              JNS     $cmp_pos          ; compare exponents and mantissas
  50.              CALL    CmpAbsValue       ; call expo. & mant. compare for neg. num
  51.              JZ      $exit1            ; if numbers equal exit
  52.              CMC                       ; else complement carry flag for neg. num
  53.              RET                       ; done
  54. $cmp_pos:    CALL    CmpAbsValue       ; compare two positive numbers
  55.              RET                       ; done
  56. RCmp         ENDP
  57.  
  58.              ALIGN   4
  59.  
  60. CmpAbsValue  PROC    NEAR
  61.              CMP     AL, CL            ; compare exponents
  62.              JNZ     $end              ; not equal, ->
  63.              OR      AL, AL            ; equal, but both zero ?
  64.              JZ      $end              ; yes
  65. CmpAbsValue  ENDP
  66.  
  67. CmpMantissa  PROC    NEAR
  68.              CMP     DX, DI            ; compare
  69.              JNZ     $end              ;  mantissa bytes
  70.              CMP     BX, SI            ;   from msb
  71.              JNZ     $end              ;    to lsb and exit
  72.              CMP     AH, CH            ;     if unequal or all equal
  73. $end:        RET                       ; done
  74. CmpMantissa  ENDP
  75.  
  76.              ALIGN   4
  77.  
  78. CODE         ENDS
  79.  
  80.              END
  81.